import Vue from 'vue'
import Vuex from "vuex";

import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);


const getDefaultState = () => {
  return {
    userInfo:  {},
    type: "", 
  }
}

const state = getDefaultState();

// 创建一个新的 store 实例
const store = new Vuex.Store({
  state,
  mutations: {
    setUserInfo(state, payload) {
      state.userInfo = payload;
    },
  
    setType(state, payload) {
      state.type = payload;
    },
  },
  actions: {
    login({ commit }) {
   
    },
  },
  plugins: [createPersistedState({
    storage: window.localStorage,
    reducer(val) {
      return {
        userInfo: val.userInfo,
      };
    }
  }), createPersistedState({
    storage: window.sessionStorage,
    reducer(val) {
      return {
        type: val.type,
      };
    }
  })]
})

export default store
